package com.wenjie.terminal.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.wenjie.terminal.MainActivity;
import com.wenjie.terminal.util.CLog;

import java.util.Objects;

/**
 * 系统启动广播监听
 */
public class BootReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        CLog.d("接收到系统广播");

        if (Objects.equals(intent.getAction(), Intent.ACTION_BOOT_COMPLETED)) {
            CLog.d("===> 系统已启动");

            // 监听到系统启动，打开主页面
            Intent activityIntent = new Intent(context, MainActivity.class);
            activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(activityIntent);
        }
    }
}